home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / astronut.src < prev    next >
Text File  |  1991-05-29  |  6KB  |  227 lines

  1. %%HP: T(3)A(R)F(.);
  2. @ ASTRONUT, by Kevin Jessup
  3. @
  4. DIR                   @ AstroNUT directory
  5.  
  6.   PLAY                @ push PLAY to start
  7.     \<< RCLF 3 FIX    @ save flags
  8. -19 CF # 83h # 40h    @ create a blank PICT
  9. BLANK PICT STO 1 CF   @ clear the crash flag
  10. 170 'ht' STO          @ set height to 170 feet
  11. -20 'v' STO 5         @ set vertical v to -20
  12.       IF RAND .5 <    @ set horiz v to 5 or -5
  13.       THEN NEG
  14.       END 'hv' STO
  15. RAND 80 * IP 'x'      @ random horiz position
  16. STO 100 'fuel' STO    @ 100 unit of fuel
  17. 2 CF                  @ clear the bottom flag
  18. MAKBOTTOM { # 0h      @ random terrain coordinates
  19. # 0h } PVIEW MAIN     @ display and loop on main
  20. CRASHht 'ht' STO      @ display landing parameters
  21. CRASHx 'x' STO
  22. CRASHv 'v' STO
  23. STATUS PICT NEWC      @ display landing position
  24. SHIP GXOR PICT {      @ display AstroNUT or CRASH
  25. # 5h # 5h }
  26.       IF CRASHv -4    @ test slope, vv and hv
  27. < CRASHsl ABS .084
  28. > OR hv OR
  29.       THEN
  30. "*CRASH*" LOOSE
  31.       ELSE PICT 7
  32. 'ht' STO+ 1 'x'
  33. STO+ NEWC aflag REPL
  34. "AstroNUT" WIN
  35.       END 3 \->GROB
  36. REPL 7 FREEZE         @ freeze the display
  37. globals PURGE         @ purge temporary globals
  38.       WHILE KEY       @ flush any excess keys
  39.       REPEAT DROP
  40.       END STOF        @ restore flags and quit
  41.     \>>
  42.  
  43.   WIN                 @ Play the WIN tune.
  44.     \<< 125           @ "I am not a musician!"
  45.       DO DUP .02
  46. BEEP 2 *
  47.       UNTIL DUP
  48. 4000 >
  49.       END DROP
  50.     \>>
  51.  
  52.   LOOSE               @ Play the LOOSE tune
  53.     \<< 4000
  54.       DO DUP .02
  55. BEEP 2 /
  56.       UNTIL DUP 125
  57. <
  58.       END DROP
  59.     \>>
  60.  
  61.   MAIN                @ main processing loop
  62.     \<<
  63.       DO              @ draw or erase the terraine
  64.         IF ht 56 >
  65.         THEN
  66.           IF 2 FS?
  67.           THEN
  68. ERASE 2 CF
  69.           END
  70.         ELSE
  71.           IF 2 FC?
  72.           THEN
  73. DRAWBOTTOM 2 SF
  74.           END
  75.         END STATUS    @ display flight parameters
  76. NEWC PICT OVER SHIP   @ display the lander
  77. GXOR ht 20 * .01      @ beep based on altitude
  78. BEEP v 'ht' STO+ hv   @ calculate new position
  79. 'x' STO+
  80.         IF x 124 >    @ wrap horizontal
  81. x 0 < OR
  82.         THEN x 125
  83. MOD ABS 'x' STO
  84.         END
  85. CHKBOTTOM GETKEY ag   @ see if we crashed, process keys
  86. 'v' STO+ PICT SWAP    @ acceleration increases v
  87. SHIP GXOR             @ erase old position
  88.       UNTIL 1 FS?     @ quit if we landed or crashed
  89.       END
  90.     \>>
  91.  
  92. @ CHKBOTTOM is the routine that eats all the CPU time.
  93. @ If anyone knows how to speed it up, please do so.
  94. @ It works by calculating linear regressions and then
  95. @ comparing the line slopes.
  96.  
  97.   CHKBOTTOM           @ set flag 1 if we crashed
  98.     \<< 1 botCOORDS   @ get terraine coordinates list size
  99. SIZE 1 -
  100.       FOR i           @ test each line segment
  101. botCOORDS i GETI 3    @ get line endpoints
  102. ROLLD GET DUP2 1      @ duplicate them
  103. GET SWAP 1 GET        @ get the x coordinates and
  104.         IF x 3 + \<=  @ see if lander is between them
  105. SWAP x 3 + > AND
  106.         THEN OVER     @ if so, compare line slopes
  107. C\->V2 CL\GS \GS+ C\->V2 \GS+ @ calculate line slope
  108. LR x DUP 'CRASHx'     @ calculate and save possible
  109. STO 3 + PREDY         @ crash x and y positions
  110. 'CRASHht' STO SWAP
  111. DROP DUP 'CRASHsl'    @ save crash slope
  112. STO SWAP C\->V2 CL\GS @ calculate slope of line to
  113. \GS+ x 3.001 + ht \->V2 @ the landers coordinates
  114. \GS+ LR SWAP DROP
  115.           IF \>=      @ if line segment slope >= the
  116.           THEN 1 SF   @ slope of line to lander,
  117.  v                    @ we crahed.  Set crash flag.
  118. 'CRASHv' STO 99 'i'   @ save crash velocity
  119. STO
  120.           END
  121.         ELSE DROP2    @ not within this line segment
  122.         END
  123.       NEXT            @ check next line
  124.     \>>
  125.  
  126.   MAKBOTTOM           @ generates a list of coordinates
  127.     \<< { } 0 120     @ get an empty list
  128.       FOR a a RAND    @ generate a random y coordinate
  129. 25 * IP 6 + 2 \->LIST
  130. 1 \->LIST + 12        @ save xy in list, do next
  131.       STEP 130 OVER   @ line up the end points so
  132. 1 GET OBJ\-> DROP     @ we don't impact on wrap
  133. SWAP DROP 2 \->LIST 1
  134. \->LIST + 9 RAND * IP @ insure at least one flat line
  135. 2 + GETI 2 GET 3
  136. ROLLD GETI 2 5 ROLL
  137. PUT SWAP 1 - SWAP
  138. PUT 'botCOORDS' STO   @ save the list
  139.     \>>
  140.  
  141.   DRAWBOTTOM          @ maps terraine coordinates to
  142.     \<< 1 botCOORDS   @ screen and display the lines
  143. SIZE 1 -
  144.       FOR i
  145. botCOORDS i GETI
  146. OBJ\-> ROT R\->B ROT 63
  147. SWAP - R\->B ROT
  148. \->LIST 3 ROLLD GET
  149. OBJ\-> ROT R\->B ROT 63
  150. SWAP - R\->B ROT
  151. \->LIST LINE
  152.       NEXT
  153.     \>>
  154.  
  155.   STATUS              @ displays the flight parameters
  156.     \<<
  157.       \<< + 1 \->GROB
  158. PICT 3 ROLLD REPL
  159.       \>> \-> s
  160.       \<< { # 54h
  161. # 0h } "Height: "
  162. ht s EVAL { # 54h
  163. # 6h } "VertV:  " v
  164. s EVAL { # 54h # Ch
  165. } "HorizV: " hv s
  166. EVAL { # 54h # 12h
  167. } "Fuel:   " fuel s
  168. EVAL
  169.       \>>
  170.     \>>
  171.  
  172.   GETKEY              @ processes keys
  173.     \<<
  174.       WHILE KEY
  175.       REPEAT
  176.         IF fuel 0 >   @ but only if we got fuel!
  177.         THEN
  178.           CASE DUP
  179. 72 ==
  180.             THEN -1
  181. 'hv' STO+ -1 'fuel'
  182. STO+
  183.             END DUP
  184. 74 ==
  185.             THEN 1
  186. 'hv' STO+ -1 'fuel'
  187. STO+
  188.             END DUP
  189. 63 ==
  190.             THEN
  191. thrust DUP NEG
  192. 'fuel' STO+ 'v'
  193. STO+
  194.             END
  195.           END
  196.         END DROP
  197.       END
  198.     \>>
  199.  
  200.   NEWC         @ get current screen coordiantes
  201.     \<< x R\->B 57 1 ht
  202. 57 MOD 57 / - * R\->B
  203. 2 \->LIST
  204.     \>>
  205.  
  206.   C\->V2       @ convert 2-element list to vector
  207.     \<< OBJ\-> DROP \->V2
  208.     \>>
  209.  
  210.   SHIP         @ GROB of the lander
  211. GROB 6 6 E13333E11212
  212.  
  213.   aflag        @ GROB of a flag
  214. GROB 7 7 F7747414F71010
  215.  
  216.   thrust 2     @ vertical thrust = -1/2 ag
  217.  
  218.   ag -4        @ acceleration due to gravity
  219.  
  220.   globals { \GSDAT     @ these are PURGEd
  221. CRASHv CRASHsl
  222. CRASHht CRASHx \GSPAR
  223. botCOORDS fuel x hv
  224. v ht }
  225.  
  226. END
  227.